package com.douqu.game.auth.web.response;

import com.bean.core.util.Utils;
import com.douqu.game.auth.database.model.ServerModel;
import com.douqu.game.core.e.E_PhonePlatform;
import com.douqu.game.core.e.E_ServerLabel;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.CoreUtils;

/**
 * @author wangzhenfei
 *         2017-07-26 17:12
 */
public class ServerResDto {

    private Integer id;

    private Integer areaId;

    private String name;

    private String ip;

    private Integer port;

    private Integer gmPort;

    private int status;

    private int isNew;

    private int isRecommend;

    private boolean showMoney;

    private String version;

    private boolean visible;

    public ServerResDto() {
    }

    public ServerResDto(Integer id) {
        this.id = id;
    }

    public ServerResDto(ServerModel model, int newServerId) {
        if(model != null){
            this.id = model.getId();
            this.areaId = model.getAreaId();
            if(Utils.isNullOrEmpty(model.getType()) || E_PhonePlatform.Android.equals(model.getType()))//安卓的发ip
                this.ip = model.getIp();
            else
                this.ip = model.getHost();//ios的发域名

            this.port = model.getPort();
            this.gmPort = model.getGmPort();
            this.status = model.getStatus();
            this.isRecommend = model.isRecommend() ? 1 : 0;
            this.name = model.getName();
            this.version = model.getVersion();
            this.visible = model.isVisible();

            if(status == SGCommonProto.E_SERVER_STATUS.SERVER_STATUS_CLOSE_VALUE){
                isNew = E_ServerLabel.CLOSE.getCode();
            }else {
                this.isNew = CoreUtils.inDays(model.getFirstOpenTime(), 7) ? E_ServerLabel.NEW.getCode(): E_ServerLabel.HOT.getCode();
                if(isNew == E_ServerLabel.HOT.getCode()){
                    isNew = newServerId == id ? E_ServerLabel.NEW.getCode(): E_ServerLabel.HOT.getCode();
                }
                this.showMoney = model.isShowMoney();
            }

        }

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAreaId() {
        return areaId;
    }

    public void setAreaId(Integer areaId) {
        this.areaId = areaId;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getIsNew() {
        return isNew;
    }

    public void setIsNew(int isNew) {
        this.isNew = isNew;
    }

    public int getIsRecommend() {
        return isRecommend;
    }

    public void setIsRecommend(int isRecommend) {
        this.isRecommend = isRecommend;
    }

    public Integer getGmPort() {
        return gmPort;
    }

    public void setGmPort(Integer gmPort) {
        this.gmPort = gmPort;
    }

    public boolean isShowMoney() {
        return showMoney;
    }

    public void setShowMoney(boolean showMoney) {
        this.showMoney = showMoney;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ServerResDto)) return false;

        ServerResDto that = (ServerResDto) o;

        if (!id.equals(that.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id;
    }


    @Override
    public String toString() {
        return "ServerResDto{" +
                "id=" + id +
                ", areaId=" + areaId +
                ", name='" + name + '\'' +
                ", ip='" + ip + '\'' +
                ", port=" + port +
                ", gmPort=" + gmPort +
                ", status=" + status +
                ", isNew=" + isNew +
                ", isRecommend=" + isRecommend +
                ", showMoney=" + showMoney +
                ", version='" + version + '\'' +
                '}';
    }
}
